package com.zzyl.controller.manager;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 床位管理
 *
 * @author YiSheep
 * @date 2024/08/06
 */
@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理")
@Slf4j
@RequiredArgsConstructor
public class BedController {
    final BedService bedService;

    /**
     * 新增床位
     *
     * @param dto 床位Dto
     * @return {@code ResponseResult<Void> }
     * @author YiSheep
     */
    @ApiOperation("新增床位")
    @PostMapping("/create")
    public ResponseResult<Void> create(@RequestBody BedDto dto) {
        log.info("新增床位：{}", dto);
        bedService.createBed(dto);
        return ResponseResult.success();
    }

    /**
     * 根据ID查询床位
     *
     * @param id 床位ID
     * @return {@code ResponseResult<BedVo> }
     * @author YiSheep
     */
    @ApiOperation("根据ID查询床位")
    @GetMapping("/read/{id}")
    public ResponseResult<BedVo> getBedById(@PathVariable Long id) {
        log.info("根据ID查询床位：{}", id);
        BedVo bedVo = bedService.getById(id);
        return ResponseResult.success(bedVo);
    }

    /**
     * 更新床位
     *
     * @param dto 床位Dto
     * @return {@code ResponseResult<Void> }
     * @author YiSheep
     */
    @ApiOperation("更新床位")
    @PutMapping("/update")
    public ResponseResult<Void> update(@RequestBody BedDto dto) {
        log.info("更新床位：{}", dto);
        bedService.updateBed(dto);
        return ResponseResult.success();
    }

    /**
     * 删除床位
     *
     * @param id 床位ID
     * @return {@code ResponseResult<Void> }
     * @author YiSheep
     */
    @ApiOperation("删除床位")
    @DeleteMapping("/delete/{id}")
    public ResponseResult<Void> delete(@PathVariable Long id) {
        log.info("删除床位：{}", id);
        bedService.deleteBed(id);
        return ResponseResult.success();
    }
}
